示例#1
0
MainForm::MainForm()
{
    SuspendLayout();

    _humanBoard = gcnew Board();
    _computerBoard = gcnew Board(false);

    _humanPlayer = gcnew HumanPlayer("Þaidëjas", _computerBoard);
    _computerPlayer = gcnew ComputerPlayer("Kompiuteris");


    _scoreboard = gcnew ScoreBoard(_humanPlayer, _computerPlayer, 10, 100);
    _controller = gcnew GameController(_humanPlayer, _computerPlayer, _humanBoard, _computerBoard, _scoreboard);

    _shuffleButton = CreateButton(ShuffleCharacter.ToString(), ButtonBackColor);
    _newGameButton = CreateButton(NewGameCharacter.ToString(), ButtonBackColor);
    _startGameButton = CreateButton(StartGameCharacter.ToString(), ButtonBackColor);

    SetupWindow();
    LayoutControls();

    _scoreboard->GameEnded += gcnew EventHandler(this, &MainForm::OnGameEnded);

    _shuffleButton->Click += gcnew System::EventHandler(this, &MainForm::OnShuffleButtonClick);
    _startGameButton->Click += gcnew System::EventHandler(this, &MainForm::OnStartGameButtonClick);
    _newGameButton->Click += gcnew System::EventHandler(this, &MainForm::OnNewGameButtonClick);

    ResumeLayout();

    StartNewGame();
};
示例#2
0
/////////////// Score Task Manager ///////////////
void ScoreTask()
{
	switch(ScoreState)
	{
		case -1:
		{
			transmit_dataD1(0xFFFF);
			if(startTheGame)
			{
				score = 0;
				score1 = Write7Seg(score % 10);
				score2 = Write7Seg(score / 10);
				dataScore = ((score1 << 8) + score2);
				transmit_dataD1(~dataScore);
				ScoreState = NothingScore;
			}				
			break;
		}
		case NothingScore:
		{
			ReadData = (PINC&0xF);
			if((ReadData) == IncrementMC)
			{
				ScoreState = IncrementScore;
				ScoreBoard();
			}
			break;
		}
		case IncrementScore:
		{
			ReadData = (PINC&0xF);
			if((ReadData) != IncrementMC)
			{
				ScoreState = NothingScore;
			}				
			break;
		}
		default:
		{
			transmit_dataD1(0xFFFF);
			if(startTheGame)
			{
				score = 0;
				score1 = Write7Seg(score % 10);
				score2 = Write7Seg(score / 10);
				dataScore = ((score1 << 8) + score2);
				transmit_dataD1(~dataScore);
				ScoreState = NothingScore;
			}				
			break;
		}
	}
}
示例#3
0
int main(int argc, char *argv[])
{
    Board board = loadBoard(argc, argv);
    int scoreOrig = ScoreBoard(board);
    if (scoreOrig == orangeWins) { puts("I win\n"); exit(-1); }
    else if (scoreOrig == yellowWins) { puts("You win\n"); exit(-1); }
    else {
        int move, score;
        abMinimax(true,Orange,g_maxDepth,board,move,score);
        if (g_debug) printf("Cached:%d Processed:%d\n", hits, losses);
        if (move != -1) {
            printf("%d\n",move);
            dropDisk(board, move, Orange);
            scoreOrig = ScoreBoard(board);
            if (scoreOrig == orangeWins) { puts("I win\n"); exit(-1); }
            else if (scoreOrig == yellowWins) { puts("You win\n"); exit(-1); }
            else exit(0);
        } else {
            puts("No move possible");
            exit(-1);
        }
    }
    return 0;
}
示例#4
0
void abMinimax(bool maximizeOrMinimize, char color, int depth, Board& board, int& move, int& score)
{
    int bestScore=maximizeOrMinimize?-10000000:10000000;
    int bestMove=-1;
    for (int column=0; column<width; column++) {
	if (GetCell(board._slots,0,column)!=Barren) continue;
	int rowFilled = dropDisk(board, column, color);
	if (rowFilled == -1)
	    continue;
	int s = ScoreBoard(board);
	if (s == (maximizeOrMinimize?orangeWins:yellowWins)) {
	    bestMove = column;
	    bestScore = s;
	    SetCell(board._slots,rowFilled,column,Barren);
	    break;
	}
	int moveInner, scoreInner;
	if (depth>1)
	    abMinimax(!maximizeOrMinimize, color==Orange?Yellow:Orange, depth-1, board, moveInner, scoreInner);
	else {
	    moveInner = -1;
	    scoreInner = s;
	}
	SetCell(board._slots,rowFilled,column, Barren);
	/* when loss is certain, avoid forfeiting the match, by shifting scores by depth... */
	if (scoreInner == orangeWins || scoreInner == yellowWins)
	    scoreInner -= depth * (int)color;
	if (depth == g_maxDepth && g_debug)
	    printf("Depth %d, placing on %d, score:%d\n", depth, column, scoreInner);
	if (maximizeOrMinimize) {
	    if (scoreInner>=bestScore) {
		bestScore = scoreInner;
		bestMove = column;
	    }
	} else {
	    if (scoreInner<=bestScore) {
		bestScore = scoreInner;
		bestMove = column;
	    }
	}
    }
    move = bestMove;
    score = bestScore;
}
示例#5
0
int main()
{
    int driver=0, mode=VESA_640x480x8bit;
    int key, score=0, stop=0;
    int isMoveable;
    int i, j;
    for (i=0; i<24 ; i++ )        /*initialize the game, borders are occupied, and each box is colored with the background color 初始化,边界全被占用, 每格颜色为背景色*/
    {
        for (j=0; j<18 ; j++ )
        {
            occupationColor[i][j] = BGColor;
            if (i>=20 || j<=3 || j>=14)
            {
                occupation[i][j] = 1;
            }
            else occupation[i][j] = 0;
        }
    }
    initgraph(&driver, &mode, "");
    srand(time(NULL));            /*set random numbers 在这里设置随机数*/
    nextBrick=(int)(19*rand()/(RAND_MAX+1.0));
    InitGame();
    CreateBrick();
    ScoreBoard();
    while (!stop)
    {
        isMoveable = FallBrick();
        if (!isMoveable)
        {
            ScanFullRow();
            if (0 == locate.y)
            {
                stop = 1;
                continue;
            }
            CreateBrick();
            ScoreBoard();
        }
        delay(500);
        while(bioskey(1) != 0)
        {
            key = bioskey(0);
            switch (key)
            {
            case ESC:
                stop = 1;
                isMoveable = 1;
                break;
            case UP:
                RotateBrick();
                break;
            case DOWN:
                MoveBrick(key);
                break;
            case LEFT:
                MoveBrick(key);
                break;
            case RIGHT:
                MoveBrick(key);
                break;
            }
        }
    }
    setcolor(RED);
    outtextxy((_LeftEdge + _RightEdge)/2, _Bottom/2, "GAME OVER!");
    setcolor(WHITE);
    outtextxy((_LeftEdge + _RightEdge)/2-40, _Bottom/2 + BrickSIZE, "Press any key to quit.");
    while (bioskey(1) == 0)
    {

    }
    closegraph();
    return 0;
}
示例#6
0
void InitGame(void)
{
    setfillstyle(SOLID_FILL, BGColor);
    bar(_LeftEdge, 0, _RightEdge-1, _Bottom-1);
    ScoreBoard();
}