예제 #1
0
파일: kernel.c 프로젝트: kshmir/Arqui-2011
// Just counts ticks and updates the cursor.
void int_08() {
	
	
	showHour();
	printKeyboard();
	printSound();
	ticks++;
	cursor_ticks++;
	if (cursor_ticks % 5 == 0)
		if (hardCursorEnabled) {
			cursorEnabled = !cursorEnabled;
			if (cursorEnabled)
				_setCursor(videoPos / 2);
			else
				_setCursor(-1);
		}
		
}
예제 #2
0
void singlePlayer(GlobalState* globalData) {
    static int tempScore = 0;
    static int transition = 0;
    static int movedone = 0;
    // First time playing?
    // Read first time from SRAM
    if (globalData->firstTime == TRUE) {
        if (globalData->newKeyboard) {
            printKeyboard(globalData, "NAME?", 5);
        } else {
            processKeyboard(globalData, game.name, 5);
        }
    }
    if (globalData->doneKeyboard) {
        globalData->firstTime = FALSE;


        if (globalData->newGame) {
            globalData->newGame = 0;
            // Setup new game
            setupGame();
            tempScore = 0;
            transition = 0;
            game.turn = rand() % 2;
            printGame(globalData);
            getCards(); // Assume cards already read by interrupts on switches (?)
        }


        // Wait till someone presses D to continue
        if (globalData->keyPress == 0x0D) {
            transition = 1;
        }

        // Begin game with computer
        if (transition) {
            if (!game.gameOver) {
                // Situation depends on game.turn
                if (game.turn) {
                    if (game.moveSel == 0) {
                        pickMove(globalData);
                    }
                    if (game.moveSel == 1) {

                        tempScore = game.oppScore;
                        game.oppScore = attack(game.myMove, game.myMonster, game.oppScore);
                        if (game.oppScore == tempScore) {
                            prints(0, 10, RED, BLACK, "                    ", 1);
                            prints(0, 18, RED, BLACK, "                    ", 1);
                            prints(0, 26, RED, BLACK, "                    ", 1);
                            prints(0, 10, RED, BLACK, "Missed!", 1);
                        } else {
                            prints(0, 10, RED, BLACK, "                    ", 1);
                            prints(0, 18, RED, BLACK, "                    ", 1);
                            prints(0, 26, RED, BLACK, "                    ", 1);
                            prints(0, 10, RED, BLACK, "Your", 1);
                            printrs(30, 10, RED, BLACK, game.myMonster->monsterName, 1);
                            prints(84, 10, RED, BLACK, "used", 1);
                            printrs(0, 18, RED, BLACK, game.myMove->moveName, 1);
                            prints(0, 26, RED, BLACK, "-    ", 1);
                            integerprint(6, 26, RED, BLACK, tempScore - game.oppScore, 1);
                        }
                        game.moveSel = 0;
                        movedone = 1;
                    }
                } else {
                    // Computer randomly picks a monster and attack
                    game.oppMonster = &myMonsterList[rand() % 3 ];
                    game.oppMove = &game.oppMonster->movelist[rand() % 3];
                    tempScore = game.myScore;
                    game.myScore = attack(game.oppMove, game.oppMonster, game.myScore);
                    if (game.myScore == tempScore) {
                        prints(0, 10, RED, BLACK, "                    ", 1);
                        prints(0, 18, RED, BLACK, "                    ", 1);
                        prints(0, 26, RED, BLACK, "                    ", 1);
                        prints(0, 10, RED, BLACK, "Enmy Missed!", 1);
                    } else {
                        prints(0, 10, RED, BLACK, "                    ", 1);
                        prints(0, 18, RED, BLACK, "                    ", 1);
                        prints(0, 26, RED, BLACK, "                    ", 1);
                        prints(0, 10, RED, BLACK, "Enmy", 1);
                        printrs(30, 10, RED, BLACK, game.oppMonster->monsterName, 1);
                        prints(84, 10, RED, BLACK, "used", 1);
                        printrs(0, 18, RED, BLACK, game.oppMove->moveName, 1);
                        prints(0, 26, RED, BLACK, "-    ", 1);
                        integerprint(6, 26, RED, BLACK, tempScore - game.myScore, 1);
                    }
                    movedone = 1;
                }

                if (movedone == 1) {
                    prints(0, 40, YELLOW, BLACK, "Your Score: ", 1);
                    prints(0, 55, YELLOW, BLACK, "     ", 1);
                    integerprint(0, 55, YELLOW, BLACK, game.myScore, 1);
                    prints(0, 70, WHITE, BLACK, "Opponent Score: ", 1);
                    prints(0, 85, WHITE, BLACK, "     ", 1);
                    integerprint(0, 85, WHITE, BLACK, game.oppScore, 1);
                    // Check game status
                    game.gameOver = gameStatus();
                    game.turn = !game.turn;
                    transition = 0;
                    movedone = 0;
                }
                //                if (game.gameOver == 1) {
                //                    if (globalData->newGame == 0) {
                //                        printResults();
                //                    }
                //                }
            } else {
                if (globalData->newGame == 0) {
                    printResults();
                }
            }
        }
        // Display results once there is a lost
    }
}
예제 #3
0
int main(int argc, char *argv[])
{
	int status = 0;
	int print = 0;
	char *mapName = NULL;
	char *saveName = NULL;
	char *dirName = NULL;
	char opt;
	int count;

	setlocale(LC_ALL, getenv(ENV_LANG));
	textdomain("keymap");

	// Graphics enabled?
	graphics = graphicsAreEnabled();

	// Check options
	while (strchr("psT:?", (opt = getopt(argc, argv, "ps:T"))))
	{
		switch (opt)
		{
			case 'p':
				// Just print out the map, if we're in text mode
				print = 1;
				break;

			case 's':
				// Save the map to a file
				if (!optarg)
				{
					fprintf(stderr, "%s", _("Missing filename argument for -s "
						"option\n"));
					usage(argv[0]);
					return (status = ERR_NULLPARAMETER);
				}
				saveName = optarg;
				break;

			case 'T':
				// Force text mode
				graphics = 0;
				break;

			case ':':
				fprintf(stderr, _("Missing parameter for %s option\n"),
					argv[optind - 1]);
				usage(argv[0]);
				return (status = ERR_NULLPARAMETER);

			default:
				fprintf(stderr, _("Unknown option '%c'\n"), optopt);
				usage(argv[0]);
				return (status = ERR_INVALID);
		}
	}

	cwd = malloc(MAX_PATH_LENGTH);
	selectedMap = malloc(sizeof(keyMap));
	if (!cwd || !selectedMap)
	{
		status = ERR_MEMORY;
		goto out;
	}

	strncpy(cwd, PATH_SYSTEM_KEYMAPS, MAX_PATH_LENGTH);

	// Get the current map
	status = keyboardGetMap(selectedMap);
	if (status < 0)
		goto out;

	strncpy(currentName, selectedMap->name, KEYMAP_NAMELEN);
	mapName = selectedMap->name;

	// Did the user supply either a map name or a key map file name?
	if ((argc > 1) && (optind < argc))
	{
		// Is it a file name?
		status = fileFind(argv[optind], NULL);
		if (status >= 0)
		{
			status = readMap(argv[optind], selectedMap);
			if (status < 0)
				goto out;

			mapName = selectedMap->name;

			dirName = dirname(argv[optind]);
			if (dirName)
			{
				strncpy(cwd, dirName, MAX_PATH_LENGTH);
				free(dirName);
			}
		}
		else
		{
			// Assume we've been given a map name.
			mapName = argv[optind];
		}

		if (!graphics && !saveName && !print)
		{
			// The user wants to set the current keyboard map to the supplied
			// name.
			status = setMap(mapName);
			goto out;
		}

		// Load the supplied map name
		status = loadMap(mapName);
		if (status < 0)
			goto out;
	}

	keyArray = malloc(KEYBOARD_SCAN_CODES * sizeof(scanKey));
	if (!keyArray)
	{
		status = ERR_MEMORY;
		goto out;
	}

	// Make the initial key array based on the current map.
	makeKeyArray(selectedMap);

	if (saveName)
	{
		// The user wants to save the current keyboard map to the supplied
		// file name.
		status = saveMap(saveName);
		goto out;
	}

	status = getMapNameParams();
	if (status < 0)
		goto out;

	if (graphics)
	{
		// Make our window
		constructWindow();

		// Run the GUI
		windowGuiRun();

		// ...and when we come back...
		windowDestroy(window);
	}
	else
	{
		if (print)
		{
			// Print out the whole keyboard for the selected map
			printKeyboard();
		}
		else
		{
			// Just print the list of map names
			printf("\n");

			for (count = 0; count < numMapNames; count ++)
				printf("%s%s\n", mapListParams[count].text,
					(!strcmp(mapListParams[count].text, selectedMap->name)?
						_(" (current)") : ""));
		}
	}

	status = 0;

out:
	if (cwd)
		free(cwd);
	if (selectedMap)
		free(selectedMap);
	if (mapListParams)
		free(mapListParams);
	if (keyArray)
		free(keyArray);

	return (status);
}